package study.doc.html.jsoup;

import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Node;
import org.junit.Test;

import java.util.List;

@Slf4j
public class QuesTest {

    String bodyHtml = "</p><p>12321312<img height=\"81\" src=\"https://k12-t-1252350207.cos.ap-beijing.myqcloud.com/vod/media/source/k12-tiku/S1011609020255408128.png\" width=\"246\"></p>";

    @Test
    public void test() {
        //
        Document doc = Jsoup.parseBodyFragment(bodyHtml);
        //
        List<Node> nodeLt = doc.body().childNodes();
        print(nodeLt);
//        nodeLt.forEach(e -> {
//
//            log.info("{}, {}", e.nodeName(), e.childNodeSize());
//        });
    }

    private int counter = 0;

    public void print(List<Node> nodeLt) {
        counter++;
        nodeLt.forEach(e -> {
            log.info("{}, {}", e.nodeName(), e.outerHtml());
            List<Node> tt = e.childNodes();
            if (CollectionUtil.isNotEmpty(tt)) {
                print(tt);
            }
        });
    }
}
